<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<sec:authentication property="principal" var="currentPrincipal" scope="page" />

<div class="modal-dialog x-modal-dialog" style="width:600px; margin-top: 150px;">

  <div class="modal-content">

    <div class="modal-header x-breadcrumb no-bottom-border clearfix">

      <h2><i class="glyphicon glyphicon-fire" title="更改时间"></i>&nbsp;&nbsp;更改时间</h2>

      <button type="button" class="close" data-dismiss="modal">&times;</button>

    </div>

    <form class="form-horizontal" method="POST" action="${ctx.host}/expiry-schedules/${schedule.id}/time" data-validate="true">

     <input type="hidden" name="_method" value="PATCH">
     <input type="hidden" name="scheduleId" value="${schedule.id}">
     <input type="hidden" name="isYear" value="${schedule.courseType.year}">
    
      <div class="modal-body">
        <div class="form-group x-form-group coach-item">
          <label class="col-xs-3 control-label">门店</label>
          <div class="pull-left col-xs-8">
            <c:choose>
              <c:when test="${currentPrincipal.siteManager or currentPrincipal.siteServer}">
                <p>${currentPrincipal.site.name}</p>
                <input type="hidden" name="siteId" value="${currentPrincipal.site.id}">
              </c:when>
              <c:otherwise>
                <c:choose>
                  <c:when test="${schedule.course.give}">
                    <p>${schedule.site.name}</p>
                    <input type="hidden" name="siteId" value="${schedule.site.id}">
                  </c:when>
                  <c:otherwise>
                    <select name="siteId" class="form-control siteSelect" data-validate="required">
                      <option value=""></option>
                      <c:forEach var="site" items="${persist.getSites(currentPrincipal.id)}">
                        <option value="${site.id}" ${schedule.site.id == site.id ? 'selected' : ''}>${site.name}</option>
                      </c:forEach>
                    </select>
                  </c:otherwise>
                </c:choose>
              </c:otherwise>
            </c:choose>
          </div>
        </div>
        
      <!--   <div class="form-group x-form-group coach-item">
          <label class="col-xs-3 control-label">教练</label>
          <div class="pull-left col-xs-8">
            <select name="coachId" class="form-control" data-validate="required">
              <option value=""></option>
              <c:forEach var="principal" items="${schedule.courseType.year ? coaches : persist.coaches(currentPrincipal.id)}">
                 <option value="${principal.id}" ${schedule.coach.id == principal.id ? 'selected' : ''}>${principal.name}</option>
              </c:forEach>
            </select>
          </div>
        </div> -->

          <div class="form-group x-form-group coach-item">
          <label class="col-xs-3 control-label">教练</label>
          <div class="pull-left col-xs-8">
            <select name="coachId" class="form-control" data-validate="required">
              <option value=""></option>
              <c:forEach var="coach" items="${coaches}">
                 <option value="${coach.id}" ${schedule.coach.id == coach.id ? 'selected' : ''}>${coach.name}</option>
              </c:forEach>
            </select>
          </div>
        </div>
      
        <div class="form-group x-form-group">
          <label class="col-xs-3 control-label text-right">日期:</label>
          <div class="pull-left col-xs-8">
            <input type="text" class="form-control date" name="occurDate" value="${schedule.occurDate}" data-validate="required"/>
          </div>
        </div>
        <div class="form-group x-form-group">
          <label class="col-xs-3 control-label text-right">时间:</label>
          <div class="pull-left col-xs-8">
            <select name="occurHour" class="form-control" data-validate="required">
              <option value=""></option>
              <c:choose>
                <c:when test="${schedule.courseType.individual and schedule.course.experience}">
                  <c:forEach var="hour" items="${schedule.site.expAppointTimes}">
                  <c:set var="hours" value="${fn:split(hour, ':')}"/>
                  <option value="${hour}" ${schedule.occurHour eq hour ? 'selected' : ''}>${hour} ~ ${hours[1] eq '00' ? (hours[0] + 1) : (hours[0] + 2)}:${hours[1] eq '00' ? '30' : '00'}</option>
              </c:forEach>
                </c:when>
                <c:otherwise>
                  <c:forEach var="hour" items="${schedule.site.appointTimes}">
                    <c:set var="hours" value="${fn:split(hour, ':')}"/>
                    <option value="${hour}" ${schedule.occurHour eq hour ? 'selected' : ''}>${hour} ~ ${hours[0] + 1}:${hours[1]}</option>
                  </c:forEach>
                </c:otherwise>
              </c:choose>
              
            </select>
          </div>
        </div>
      </div>
      
      <div class="modal-footer clearfix">
        <button type="submit" class="btn btn-success btn-shadow btn-shadow-success x-btn">确定</button>&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-default btn-shadow btn-shadow-default x-btn" data-dismiss="modal">取消</button>
      </div>
    </form>

  </div>

</div>

<script>
  $('select[name="siteId"]').select2({
      minimumResultsForSearch : -1,
  })

  $('select[name="coachId"]').select2({
    placeholder : '请选择教练',
    minimumResultsForSearch : 5,
    allowClear : true,
  });

  console.log($('select[name="coachId"]').val())
  
  $('.date').datetimepicker({
      format: 'yyyy-mm-dd',
      autoclose: true,
      language: 'zh-CN',
      todayBtn: 'linked',
      startDate: new Date(),
      todayHighlight: true,
      pickerPosition: 'bottom-right',
      minView: 'month'
   })
 
     $('select[name="occurHour"]').select2({
       placeholder : '请选择具体时间段',
       minimumResultsForSearch : 5,
       allowClear : true,
     });
</script>

